<?php
Yii::app()->clientScript->registerScript('search', "
$('#search-button').toggle(function(){
	$('.search-form').toggle('slow');
	$(this).html('Masquer le formulaire de recherche');
	return false;
}, function(){
	$('.search-form').toggle('slow');
	$(this).html('Afficher le formulaire de recherche');
	return false;
});
$('#init-button').click(function(){
	$(':input','.search-form form')
		.not(':button, :submit, :reset, :hidden')
		.val('')
		.removeAttr('checked')
		.removeAttr('selected');
	$('select option:selected').removeAttr('selected');
	$('#offre-grid').yiiGridView('update', {
		data: '',
		url: '" . ($compte ? Yii::app()->createUrl('offre/compte') : Yii::app()->createUrl('offre/admin')) . "'
	});
	return false;
});
$('.search-form form').submit(function(){
	$('#offre-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
");
?>


<div class="container">
	
	<?php if(Yii::app()->user->hasFlash('offre')) {?>
	<div class="row">
		<div class="col-lg-12">
			<div class="alert alert-success alert-dismissable">
				<button type="button" class="close" data-dismiss="alert"
					aria-hidden="true">&times;</button>
				<?php echo Yii::app()->user->getFlash('offre'); ?>
				<?php
				Yii::app()->clientScript->registerScript('close-alert', "
					window.setTimeout(function() { $('.alert').alert('close'); }, 4000);
				");
				?>
			</div>
		</div>
	</div>
	<?php } ?>
	
	<div class="row">
		<div class="col-lg-12">
			<?php if ($compte) {?>
			<h1>Mes offres</h1>
			<?php } else {?>
			<h1>Liste des offres</h1>
			<?php }?>
			</div>
	</div>
	<div class="row">
		<div class="col-lg-12">			
			<?php echo CHtml::link('Afficher le formulaire de recherche','#',array("class"=>"btn btn-mini btn-info","id"=>"search-button"));?>					
		</div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<div class="search-form" style="display: none">
			<?php $this->renderPartial('_search',array(
				'model'=>$model
			)); ?>
			</div>
			<!-- search-form -->

			<?php $this->widget('ext.bs3gridview.widgets.Bs3GridView', array(
				'id'=>'offre-grid',
				'dataProvider'=>$model->search(),
				'columns'=>array(
					'id',
					array (
							'name' => 'Demandeur',
							'type' => 'html',
							'value'=>'$data->iddemande0->idseliste . (($data->iddemande0->idseliste0->v_pseudo == 1 || Yii::app()->user->id == $data->iddemande0->idseliste || Yii::app()->user->admin) ? " (" . $data->iddemande0->idseliste0->pseudo . ")" : "")'
					),
					array (
							'name' => 'Grain',
							'type' => 'html',
							'value' => '$data->iddemande0->idgrain0->idtype0->lib . " / " . $data->iddemande0->idgrain0->iddomaine0->lib . " / " . $data->iddemande0->idgrain0->nom'
					),
					array (
							'name' => 'idseliste',
							'type' => 'html',
							'value'=>'$data->idseliste . (($data->idseliste0->v_pseudo == 1 || Yii::app()->user->id == $data->idseliste || Yii::app()->user->admin) ? " (" . $data->idseliste0->pseudo . ")" : "")',
							'visible'=>!$compte
					),	
					array(
							'name'=>'date_offre',
							'value'=>'Yii::app()->dateFormatter->format(\'dd/MM/yyyy\',$data->date_offre)',
					),
					array(
							'name'=>'date_propose',
							'value'=>'Yii::app()->dateFormatter->format(\'dd/MM/yyyy\',$data->date_propose)',
					),
					array(
							'name'=>'status',
							'value'=>'$data->getStatus()'
					),
					array(
						'class'=>'CButtonColumn',
						'header'=>'Actions',
						'template' => '{view} {update} {delete}',
						'viewButtonImageUrl' => false,
						'updateButtonImageUrl' => false, 
						'deleteButtonImageUrl' => false, 
						'buttons'=>array(
									'view'=>array(
											'label'=>"",
											'options'=>array(
													"class"=>"glyphicon glyphicon-search",
													"title"=>"Voir"
											),
									),
									'update'=>array(
											'label'=>"",
											'options'=>array(
												"class"=>"glyphicon glyphicon-edit",
												"title"=>"Mettre à jour"
												),
										),
									'delete'=>array(
											'label'=>"",
											'options'=>array(
												"class"=>"glyphicon glyphicon-remove",
												"title"=>"Supprimer"
												),
										),  
									),  
					),
				),
			)); ?>
		</div>
	</div>
</div>